package com.hengtongxing.hejiayun.shop.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.recyclerview.widget.RecyclerView;

import com.hengtongxing.hejiayun.R;
import com.hengtongxing.hejiayun.utils.GlideUtils;
import com.hengtongxing.hejiayun.widget.RoundImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author:HWC
 * Time:2019/11/28
 * Description:
 */
public class DynamicPicAdapter extends RecyclerView.Adapter<DynamicPicAdapter.ViewHolder> {

    private OnItemClickListener listener;
    private List<String> dataBeans;
    private Context context;

    public DynamicPicAdapter(Context context, List<String> dataBeans) {
        this.context = context;
        this.dataBeans = dataBeans;
    }

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_home_dynamic_pic, viewGroup, false);
        ViewHolder holder = new ViewHolder(inflate);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        String dataBean = dataBeans.get(position);
        GlideUtils.loadImage(context, viewHolder.iv_shopIc, dataBean);
        viewHolder.itemView.setTag(position);
        viewHolder.itemView.setOnClickListener(view -> {
            listener.onItemClick(position);
        });
    }

    @Override
    public int getItemCount() {
        return dataBeans == null ? 0 : dataBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_shopIc)
        RoundImageView iv_shopIc;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
